﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataAccess;
namespace XuaNhapKho
{
    public partial class HoaDon : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["User"] == null)
                {
                    Response.Redirect("/Default.aspx");
                }
                else
                {
                    
                }

                loadGridView();


                DataSet ds = HoaDonDAO.GetReport();

                foreach (DataRow rows in ds.Tables[0].Rows)
                {
                    ltlTongHoaDon.Text = rows["TongHoaDon"].ToString();
                    ltlTongHoaDonNhap.Text = rows["TongHoaDonNhap"].ToString();
                    ltlTongHoaDonXuat.Text = rows["TongHoaDonXuat"].ToString();


                    ltlTongTien.Text = String.Format("{0:0,0}", double.Parse(rows["TongTien"].ToString()));
                    ltlTongTienNo.Text = String.Format("{0:0,0}", double.Parse(rows["TongTienNo"].ToString()));
                    ltlTongTienThu.Text = String.Format("{0:0,0}", double.Parse(rows["TongTienTra"].ToString()));

                }


            }
        }

        public void loadGridView()
        {
            grvHoaDon.DataSource = HoaDonDAO.GetAll();
            grvHoaDon.DataBind();
        }
        protected void grvHoaDon_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvHoaDon.PageIndex = e.NewPageIndex;
            loadGridView();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string mahoadon = txtMaHoaDon.Text;
            int loaihoadon = int.Parse(ddlLoaiHoaDon.SelectedValue);

            grvHoaDon.DataSource = HoaDonDAO.Search(mahoadon, loaihoadon); ;
            grvHoaDon.DataBind();

        }

        protected void lbtnDetail_Command(object sender, CommandEventArgs e)
        {
            Response.Redirect("/ChiTietHoaDon.aspx?id=" + e.CommandArgument.ToString()+"&type="+e.CommandName.ToString());
        }
    }
}